from django.db import models


# Create your models here.
class Department(models.Model):
    title = models.CharField(verbose_name="部门", max_length=32)

    def __str__(self):
        return self.title


class UserInfo(models.Model):
    name = models.CharField(verbose_name="姓名", max_length=16)
    password = models.CharField(verbose_name="密码", max_length=64)
    # 在django中做约束
    gender_choices = (
        (1, "男"),
        (2, "女"),
    )
    gender = models.SmallIntegerField(verbose_name="性别", choices=gender_choices)
    age = models.IntegerField(verbose_name="年龄")
    account = models.DecimalField(verbose_name="账户余额", max_digits=10, decimal_places=2, default=0)
    create_time = models.DateField(verbose_name="入职时间")

    # 在数据库表中做约束
    depart = models.ForeignKey(verbose_name="部门", to="Department", to_field="id", null=True, blank=None,
                               on_delete=models.SET_NULL)
    # 上方为置空，需要设置字段null=True, blank=None可空，下方为级联删除，
    # depart = models.ForeignKey(to="Department", to_field="id", on_delete=models.CASCADE)


class Mobile(models.Model):
    mobile = models.CharField(max_length=11, verbose_name="手机号")
    price = models.DecimalField(max_digits=10, decimal_places=2, verbose_name="价格")

    level_choices = (
        (1, "王者"),
        (2, "钻石"),
        (3, "铂金"),
        (4, "黄金"),
        (5, "白银"),
    )
    level = models.SmallIntegerField(verbose_name="级别", choices=level_choices)

    status = models.SmallIntegerField(verbose_name="状态", choices=((1, "已占用"), (0, "未占用")))


class Admin(models.Model):
    username = models.CharField(verbose_name='用户名',max_length=32)
    password = models.CharField(verbose_name='密码',max_length=64)
